package com.hxtec.polaris.controller;

import com.hxtec.polaris.commons.aop.Log;
import com.hxtec.polaris.commons.api.vo.Result;
import com.hxtec.polaris.commons.dto.OmsOrderDeliveryParam;
import com.hxtec.polaris.entity.ShopLogisticCompany;
import com.hxtec.polaris.service.OrderManagerService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Describtion OMS 相关
 * @Author yonyong
 * @Date 2019/12/23 14:29
 * @Version 1.0.0
 **/
@RestController
@RequestMapping(value = "orderMng",produces = "application/json;charset=utf-8")
@CrossOrigin
@Api(value = "/orderMng", tags = "订单相关")
public class OrderManagerController {

    @Autowired
    OrderManagerService orderManagerService;

    @GetMapping("list")
    public Object list(int pageNum,int pageSize,String orderSn,String receiverKeyword,String status,String updateTime){
        return orderManagerService.list(pageNum,pageSize,orderSn,receiverKeyword,status,updateTime);
    }

    @GetMapping("getDetail")
    public Object getDetail(int id){
        return Result.ok(orderManagerService.getDetail(id));
    }

    @PostMapping("update/close")
    @Log(value = "订单关闭",comment = "管理员关闭订单")
    public Object closeOrder(String ids,String note){
        String[] idss = ids.split(",");
        return Result.ok(orderManagerService.closeOrder(idss,note));
    }

    @PostMapping("update/delivery")
    @Log(value = "订单发货",comment = "管理员执行发货操作")
    public Object delivery(@RequestBody List<OmsOrderDeliveryParam> deliveryParamList){
        int count = orderManagerService.delivery(deliveryParamList);
        if (count > 0) {
            return Result.ok(count);
        }
        return Result.error();
    }

    @PostMapping("update/receiverInfo")
    @Log(value = "修改收货人信息",comment = "管理员修改订单收货人信息")
    public Object receiverInfo(int id,String name,String phone,String postcode,String detail){
        int count = orderManagerService.receiverInfo(id,name,phone,postcode,detail);
        if (count > 0) {
            return Result.ok(count);
        }
        return Result.error();
    }

    @GetMapping("express/getInfo")
    public Result getExpressInfo(String company,String code){
        return Result.ok(orderManagerService.getExpressInfo(company,code));
    }

    @GetMapping("logistic/get")
    public Result getLogistic(){
        return Result.ok(orderManagerService.getLogistic());
    }

    @PostMapping("logistic/update")
    @Log(value = "更新物流公司",comment = "管理员更新物流公司")
    public Result updateLogistic(ShopLogisticCompany shopLogisticCompany){
        return Result.ok(orderManagerService.updateLogistic(shopLogisticCompany));
    }

    @PostMapping("logistic/add")
    @Log(value = "添加物流公司",comment = "管理员添加物流公司")
    public Result addLogistic(ShopLogisticCompany shopLogisticCompany){
        return Result.ok(orderManagerService.addLogistic(shopLogisticCompany));
    }

    @PostMapping("logistic/delete")
    @Log(value = "删除物流公司",comment = "管理员删除物流公司")
    public Result deleteLogistic(ShopLogisticCompany shopLogisticCompany){
        return Result.ok(orderManagerService.deleteLogistic(shopLogisticCompany));
    }

    @PostMapping("logistic/select")
    public Result selectLogistic(String name){
        return Result.ok(orderManagerService.selectLogistic(name));
    }

}
